package com.zuowei.ycy.user.adapter;

import android.content.Context;
import android.view.View;

import com.and.yzy.frame.adapter.AdapterCallback;
import com.and.yzy.frame.adapter.CommonAdapter;
import com.and.yzy.frame.adapter.ViewHolder;
import com.and.yzy.frame.util.DateTool;
import com.and.yzy.frame.view.dialog.MaterialDialog;
import com.zuowei.ycy.R;
import com.zuowei.ycy.user.domain.OrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/4/28.
 * 我的订单
 */
public class OrderAdapter extends CommonAdapter<OrderInfo> {

    private String status[] = {"待支付", "待接单", "配送中", "待收货", "待评价", "已完成", "申请取消订单中", "已取消"};

    public OrderAdapter(Context context, List<OrderInfo> mDatas, int itemLayoutId, AdapterCallback adapterCallback) {
        super(context, mDatas, itemLayoutId, adapterCallback);
    }

    @Override
    public void convert(ViewHolder holder, final OrderInfo item, int positon) {
        holder.setImageByUrl(R.id.iv_good, item.getHead_pic());
        holder.setTextViewText(R.id.tv_name, item.getShop_name());
        holder.setTextViewText(R.id.tv_price, item.getOrder_price());
        holder.setTextViewText(R.id.tv_time, "下单时间：" + DateTool.timestampToStrTime(item.getCreate_time(),""));
        holder.setTextViewText(R.id.tv_state, status[Integer.parseInt(item.getStatus())]);

        holder.getView(R.id.v_02).setVisibility(View.VISIBLE);
        int status = Integer.parseInt(item.getStatus());
        if (status == 0) {
            holder.getView(R.id.tv_btn_left).setVisibility(View.VISIBLE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.VISIBLE);
            holder.setTextViewText(R.id.tv_btn_right, "立即付款");

            holder.getView(R.id.tv_btn_right).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //去支付
                    adapterCallback.adapterInfotoActiity(item, 0);
                }
            });

            holder.setTextViewText(R.id.tv_btn_left, "取消订单");
            holder.getView(R.id.tv_btn_left).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //取消订单
                    MaterialDialog dialog = new MaterialDialog(mContext);
                    dialog.setMDTitle("提示");
                    dialog.setMDMessage("确定要取消该订单吗?");
                    dialog.setMDConfirmBtnClick(new MaterialDialog.DialogBtnCallBack() {
                        @Override
                        public void dialogBtnOnClick() {
                            adapterCallback.adapterInfotoActiity(item, 1);
                        }
                    });
                    dialog.show();
                }
            });

        } else if (status == 1) {
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.VISIBLE);
            holder.setTextViewText(R.id.tv_btn_right, "取消订单");

            holder.getView(R.id.tv_btn_right).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //取消订单
                    MaterialDialog dialog = new MaterialDialog(mContext);
                    dialog.setMDTitle("提示");
                    dialog.setMDMessage("确定要取消该订单吗?");
                    dialog.setMDConfirmBtnClick(new MaterialDialog.DialogBtnCallBack() {
                        @Override
                        public void dialogBtnOnClick() {
                            adapterCallback.adapterInfotoActiity(item, 1);
                        }
                    });
                    dialog.show();
                }
            });
        } else if (status == 2) { //待配送/配送中
            holder.getView(R.id.v_02).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.GONE);
        } else if (status == 3) {
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.VISIBLE);
            holder.setTextViewText(R.id.tv_btn_right, "确认收货");

            holder.getView(R.id.tv_btn_right).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //确认收货
                    MaterialDialog dialog = new MaterialDialog(mContext);
                    dialog.setMDTitle("提示");
                    dialog.setMDMessage("确定已收到货物，该操作不可撤销?");
                    dialog.setMDConfirmBtnClick(new MaterialDialog.DialogBtnCallBack() {
                        @Override
                        public void dialogBtnOnClick() {
                            adapterCallback.adapterInfotoActiity(item, 2);
                        }
                    });
                    dialog.show();
                }
            });
        } else if (status == 4) {
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.VISIBLE);
            holder.setTextViewText(R.id.tv_btn_right, "立即评价");

            holder.getView(R.id.tv_btn_right).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //评价
                    adapterCallback.adapterInfotoActiity(item,3);
                }
            });
        } else if (status == 5) {
            holder.getView(R.id.v_02).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.GONE);
        } else if (status == 6) {
            holder.getView(R.id.v_02).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.GONE);
        } else if (status == 7) {
            holder.getView(R.id.v_02).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_left).setVisibility(View.GONE);
            holder.getView(R.id.tv_btn_right).setVisibility(View.GONE);
        }


    }
}
